import {
  queryRoleRule,
  getRoleById,
  addRoleRule,
  enabledControl
} from '@/services/settings/user/roleService';

/**
 * 角色管理Model
 * @Author 肖家添
 * @Date 2020/3/8 19:49
 */
export default {
  namespace: 'roleModel',

  state: {},

  effects: {
    //-- 角色列表
    * fetchRole({ payload, callback }, { call, put }) {
      const response = yield call(queryRoleRule, payload);
      if(callback) callback(response);
    },
    //-- 新增角色
    * addRole({ payload, callback }, { call, put }) {
      const response = yield call(addRoleRule, payload);
      if(callback) callback(response);
    },
    //-- 获取角色
    * getRoleById({ payload, callback }, { call, put }) {
      const response = yield call(getRoleById, payload);
      if(callback) callback(response);
    },
    //-- 数据状态控制
    * enabledControl({ payload, callback }, { call, put }) {
      const response = yield call(enabledControl, payload);
      if(callback) callback(response);
      return;
    },
  },

  reducers: {}
};
